
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 05/04/2014 19:33:27
-- Generated from EDMX file: C:\svn_git_local_copy\codingdojos\trials\BookPROASPNETMVC4\Chapter3Applications\Models\PersistentModel\ShoppingListModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [ShoppingListModel];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_ProductShoppingList_Product]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProductShoppingList] DROP CONSTRAINT [FK_ProductShoppingList_Product];
GO
IF OBJECT_ID(N'[dbo].[FK_ProductShoppingList_ShoppingList]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProductShoppingList] DROP CONSTRAINT [FK_ProductShoppingList_ShoppingList];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[ProductSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProductSet];
GO
IF OBJECT_ID(N'[dbo].[ProductShoppingList]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProductShoppingList];
GO
IF OBJECT_ID(N'[dbo].[ShoppingListSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ShoppingListSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'ProductSet'
CREATE TABLE [dbo].[ProductSet] (
    [ProductId] int IDENTITY(1,1) NOT NULL,
    [ProductName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ShoppingListSet'
CREATE TABLE [dbo].[ShoppingListSet] (
    [ShoppingListId] int IDENTITY(1,1) NOT NULL,
    [ShoppingListName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ProductShoppingList'
CREATE TABLE [dbo].[ProductShoppingList] (
    [Product_ProductId] int  NOT NULL,
    [ShoppingList_ShoppingListId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ProductId] in table 'ProductSet'
ALTER TABLE [dbo].[ProductSet]
ADD CONSTRAINT [PK_ProductSet]
    PRIMARY KEY CLUSTERED ([ProductId] ASC);
GO

-- Creating primary key on [ShoppingListId] in table 'ShoppingListSet'
ALTER TABLE [dbo].[ShoppingListSet]
ADD CONSTRAINT [PK_ShoppingListSet]
    PRIMARY KEY CLUSTERED ([ShoppingListId] ASC);
GO

-- Creating primary key on [Product_ProductId], [ShoppingList_ShoppingListId] in table 'ProductShoppingList'
ALTER TABLE [dbo].[ProductShoppingList]
ADD CONSTRAINT [PK_ProductShoppingList]
    PRIMARY KEY NONCLUSTERED ([Product_ProductId], [ShoppingList_ShoppingListId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Product_ProductId] in table 'ProductShoppingList'
ALTER TABLE [dbo].[ProductShoppingList]
ADD CONSTRAINT [FK_ProductShoppingList_Product]
    FOREIGN KEY ([Product_ProductId])
    REFERENCES [dbo].[ProductSet]
        ([ProductId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ShoppingList_ShoppingListId] in table 'ProductShoppingList'
ALTER TABLE [dbo].[ProductShoppingList]
ADD CONSTRAINT [FK_ProductShoppingList_ShoppingList]
    FOREIGN KEY ([ShoppingList_ShoppingListId])
    REFERENCES [dbo].[ShoppingListSet]
        ([ShoppingListId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProductShoppingList_ShoppingList'
CREATE INDEX [IX_FK_ProductShoppingList_ShoppingList]
ON [dbo].[ProductShoppingList]
    ([ShoppingList_ShoppingListId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------